k8s YAML 小細節

前言

最近寫yaml,有時常會忘記這個的功能是什麼,就記一下吧

正文

  1. Service 的Port功能
    Port exposes the Kubernetes service on the specified port within the cluster. Other pods within the cluster can communicate with this server on the specified port.

TargetPort is the port on which the service will send requests to, that your pod will be listening on. Your application in the container will need to be listening on this port also.

NodePort exposes a service externally to the cluster by means of the target nodes IP address and the NodePort. NodePort is the default setting if the port field is not specified.

  1. 探針檢查
livenessProbe:
  initialDelaySeconds: 10
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3
  tcpSocket:
    port: 80
readinessProbe:
  initialDelaySeconds: 30
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3
  tcpSocket:
    port: 80
  1. pull image 認證
    如果要佈署的image是屬於 私密的,
    需要加上
imagePullSecrets:
  - name: regcred

要先注入Secred

kubectl create secret generic regcred --from-file=./username.txt
  1. Service 服務類型

ref.
Kubernetes的三種外部訪問方式:NodePort、LoadBalancer 和 Ingress
Kubernetes 服務

  1. kube dns

Pod DNS record

[[12.fig-3.jpg]]

  172-17-0-6.default.pod.cluster.local

Service DNS record

[[12.fig-4.jpg]]

  nginx.default.svc.cluster.local

Service Discovery

[[12.fig-5.jpg]]

  web-0.nginx.default.svc.cluster.local
  1. Auto Scaling(自動擴展)
    在Auto Scaling 裡面,有一個設定是根據cpu的使用量大小去增加Pod,
    假設
    targetCPUUtilizationPercentage:10
    在deploy 裡的request CPU 設定 200m
    表示,當cpu的使用率在 20m(200m * 10% = 20m )時,會自動擴展

如果要使用其他的指標,api 需改用 autoscaling/v2beta2
這邊還沒測試過,有需要的可至相關網頁查詢
ref.
Kubernetes 那些事 — Auto Scaling
Kubernetes--k8s--進階--全面瞭解HPA--部署HPA實現高可用和成本控制
Kubernetes 1.8: Now with 100% Daily Value of Custom Metrics